<template>
  <van-nav-bar>
    <template #title>
      <p>Happy Chat Start</p>
    </template>
    <template #left  v-if="showNavArrow">
     <div @click="back">
        <van-icon name="arrow-left" size="18" color="#ff6034" />
      返回
     </div>
    </template>
    <template #right>
      <van-icon @click="showSearch" name="search" size="18" color="#ff6034" />
    </template>
  </van-nav-bar>
</template>

<script>
export default {
  data() {
    return {
      showNavArrow: false,
    };
  },
  mounted() {
    if (this.$route.meta.showNavArrow) {
      this.showNavArrow = true;
    } else {
      this.showNavArrow = false;
    }
    console.log(this.showNavArrow);
  },
  watch: {
    '$route': function (nv, ov) {
      var that = this;
      if (nv.meta.showNavArrow) {
        that.showNavArrow = true;
      } else {
        that.showNavArrow = false;
      }
    },
  },
  methods: {
    showSearch() {
      this.$store.commit("setShowSearch", true);
    },
    back(){
      window.history.length > 1?window.history.go(-1):this.$router.replace('/');
    }
  },
};
</script>

<style lang="scss" scoped>
</style>